package com.example.api.config;

import feign.*;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;

import java.util.stream.Collectors;

@Configuration
public class FeignConfig {

    /**
     * NONE 不记录
     * BASIC 记录基本的请求行，响应状态码数据
     * HEADERS 记录基本的请求行，响应状态数据，记录响应头信息
     * FULL 记录完成的请求，响应数据
     * */
    @Bean
    public Logger.Level level(){
        return Logger.Level.FULL;
    }

    @Bean
    @ConditionalOnMissingBean
    public HttpMessageConverters messageConverters(ObjectProvider<HttpMessageConverter<?>> converters){
        return new HttpMessageConverters(converters.orderedStream().collect(Collectors.toList()));
    }

}